# Perspective camera, with interactive capabilities.
# Robert Bridson
# Released under the GPLv3

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtOpenGL import *
from OpenGL.GL import *
import transform

class Camera(object):
    """
    Camera represents a perspective camera in a scene.
    """

    def __init__(self, parent = None):
        QGLWidget.__init__(self, parent)
        self.aspect = 1.0
        self.fovy = 0.69813170079772 # 40 degrees in radians
        self.P = transform.perspective(fovy, aspect, 

    def mousePressEvent(self, event):
        pass
   
    def mouseMoveEvent(self, event):
        pass

    def mouseReleaseEvent(self, event):
        pass

    def initializeGL(self):
        glClearColor(.75, .75, .75, 1)
        glClearDepth(1)

    def resizeGL(self, w, h):
        glViewport(0, 0, w, h)
        self.aspect = float(w)/float(h)

        # and set up projection matrix to match

    def paintGL(self):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        self._renderAxes()

    def _initAxes(self):
        self.axesVertexData = VBO(array([[0.1,0.1,0.1,1], [1,0,0,1],
                                         [0.1,0.5,0.1,1], [0,1,0,1],
                                         [0.1,0.1,0.5,1], [0,0,1,1]], 'f'))
        self.axesColorData = VBO(array([[1,0,0,1], [1,0,0,1],
                                        [0,1,0,1], [0,1,0,1],
                                        [0,0,1,1], [0,0,1,1]], 'f'))

    def _renderAxes(self):
        glUseProgram(self.commonShaders.colorShader)
        self.axesVertexData.bind()
        self.axesColorData.bind()
        glEnableClientState(GL_VERTEX_ARRAY)
        glVertexPointerf(self.axesVertexData)
        glColorPointerf(self.axesColorData)
        glDrawArrays(GL_TRIANGLES, 0, 6)
        self.axesVertexData.unbind()
        self.axesColorData.unbind()
        glDisableClientState(GL_VERTEX_ARRAY)
        glUseProgram(0)

